﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace FF
{
    public partial class FormSaleReport : Form
    {
        public FormSaleReport()
        {
            InitializeComponent();
        }

        private void FormSaleReport_Load(object sender, EventArgs e)
        {
            this.dateTimePickerStart.Value = DateTime.Now.AddDays(-DateTime.Now.Day + 1);
            this.dateTimePickerEnd.Value = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day);

            //this.reportViewer1.ProcessingMode = ProcessingMode.Local;
            //reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\" +"Report1.rdlc";
            //this.reportViewer1.RefreshReport();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            string sql = "SELECT order_id,customer_id,customer_name,user_id,user_name,good_id,good_name,good_num,good_price,receiver_name,total_prices,money_receive,discount,receive_company,strftime('%Y-%m-%d',add_date) as add_date,remark FROM ff_order where 1=1  ";
            //string sql = "SELECT order_id,customer_id,customer_name,user_id,user_name,good_id,good_name,good_num,good_price,receiver_name,total_prices,money_receive,(total_prices-money_receive) as to_receive, discount,receive_company,strftime('%Y-%m-%d',add_date) as add_date,remark FROM ff_order where 1=1 ";
            sql += " and datetime(add_date) >=datetime('" + dateTimePickerStart.Value.ToString("yyyy-MM-dd") + "')";
            sql += " and datetime(add_date) <datetime('" + dateTimePickerEnd.Value.AddDays(1).ToString("yyyy-MM-dd") + "')";
            try
            {
                DataSet ds = SQLiteHelper.Query(sql);
                if (ds == null || ds.Tables.Count < 1 || ds.Tables[0].Rows.Count < 1)
                {
                    MessageBox.Show("没有相关记录！", "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //dataGridView1.DataSource = null;
                    return;
                }
               
                this.reportViewer1.LocalReport.DataSources.Clear();
                this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("myds", ds.Tables[0]));
                //传入起止日期
                ReportParameter rpStart = new ReportParameter("StartDay", dateTimePickerStart.Value.ToString("yyyy-MM-dd"));
                ReportParameter rpEnd = new ReportParameter("EndDay", dateTimePickerEnd.Value.ToString("yyyy-MM-dd"));
                this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rpStart, rpEnd });
                this.reportViewer1.RefreshReport();
                return;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("程序出错了！" + ex.Message, "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
    }
}
